package cn.findviewbydream.evil.app.test;

import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.app.test
 * 时间：16-12-19
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
public class WebSocketConfig implements WebSocketConfigurer
{
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry)
    {
        /*地址*/
        registry.addHandler(myhandler(), "/websocket")
                .addInterceptors(myInterceptors()).setAllowedOrigins("*");

        /*允许使用客户端scokjs*/
        registry.addHandler(myhandler(), "/sockjs/websocket")
                .addInterceptors(myInterceptors()).withSockJS();
    }

    @Bean
    public WebSocketHandler myhandler()
    {
        return new WebSocketEndPoint();
    }

    @Bean
    public HandshakeInterceptor myInterceptors()
    {
        return new HandshakeInterceptor();
    }
}
